package com.kgc.student.studentweb.controller;

import com.kgc.student.entity.Studentinfo;
import com.kgc.student.service.StudentinfoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StuController {
    @Reference
    StudentinfoService studentinfoService;

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Studentinfo> selectAll(){
        List<Studentinfo> studentinfos = studentinfoService.selectAll();
        return studentinfos;
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public Studentinfo selectById(Integer sid){
        Studentinfo studentinfo = studentinfoService.selectById(sid);
        return studentinfo;
    }

    @RequestMapping("/updateStu")
    @ResponseBody
    public Map<String ,Object> update(@RequestBody Studentinfo studentinfo){
        Integer integer = studentinfoService.updateStudent(studentinfo);
        Map<String,Object> map=new HashMap<>();
        if (integer>0){
            map.put("result","success");
            return map;
        }else {
         map.put("result","error");
            return map;
        }
    }
}
